﻿
Imports Cls_Common
Imports VSModel

Partial Class FrontEnd_Control_Oto_ListSalon
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindHotSalon()
            BindToGrid(Request("Id"))
        End If

    End Sub
    Protected Sub BindHotSalon()
        Using Data As New VSEntities
            Dim k As New List(Of VSModel.Store)
            Dim p = (From q In Data.Stores Where q.StatusId = 3 And ((q.PublishedDate <= Now() And (q.eEffectiveDate >= Now()) Or q.eEffectiveDate Is Nothing)) Select q).ToList
            Static rnd As New Random
            For j = 1 To 8
                Dim r As Integer = rnd.Next(p.Count)
                'get item into k
                k.Add(p(r))
                p.RemoveAt(r)
            Next j
            With rptHotSalon
                .DataSource = k
                .DataBind()
            End With
        End Using

    End Sub


    Protected Sub BindToGrid(ByVal _TinhThanhId As Integer)

        Using Data As New VSEntities
            Dim p = (From q In Data.Stores Where (q.TinhThanhId = _TinhThanhId Or _TinhThanhId = 0) _
                     And q.StatusId = 3 And ((q.PublishedDate <= Now() And (q.eEffectiveDate >= Now()) _
                      Or q.eEffectiveDate Is Nothing)) Order By q.PublishedDate Descending Select q).ToList
            With rptShow
                .DataSource = p
                .DataBind()
            End With
        End Using
    End Sub


    Protected Sub rptShow_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptShow.ItemDataBound
        Dim row = CType(e.Item.DataItem, VSModel.Store)
        Dim img As Image = CType(e.Item.FindControl("imgPreview"), Image)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        Dim hplSalonTitle As HyperLink = CType(e.Item.FindControl("hplSalonTitle"), HyperLink)

        img.ImageUrl = CookedImageURL("140-120", row.ImgLogo)
        img.AlternateText = row.Title
        img.ToolTip = row.Title
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & "salon-oto/" & row.QueryString & "-" & row.StoreId.ToString & ".html"
        hplSalonTitle.NavigateUrl = MainDomain & "salon-oto/" & row.QueryString & "-" & row.StoreId.ToString & ".html"

        Dim ltrDes As Literal = CType(e.Item.FindControl("ltrDes"), Literal)
        ltrDes.Text = row.Slogan

        Dim ltrDiaChi As Literal = CType(e.Item.FindControl("ltrDiaChi"), Literal)
        ltrDiaChi.Text = row.DiaChi

    End Sub

    Protected Sub rptHotSalon_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptHotSalon.ItemDataBound
        Dim row = CType(e.Item.DataItem, VSModel.Store)
        Dim img As Image = CType(e.Item.FindControl("imgPreview"), Image)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)
        Dim hplSalonTitle As HyperLink = CType(e.Item.FindControl("hplSalonTitle"), HyperLink)


        img.ImageUrl = CookedImageURL("140-120", row.ImgLogo)
        img.AlternateText = row.Title
        img.ToolTip = row.Title
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & "salon-oto/" & row.QueryString & "-" & row.StoreId.ToString & ".html"
        hplSalonTitle.NavigateUrl = MainDomain & "salon-oto/" & row.QueryString & "-" & row.StoreId.ToString & ".html"
        Dim ltrDes As Literal = CType(e.Item.FindControl("ltrDes"), Literal)
        ltrDes.Text = row.Slogan

        Dim ltrDiaChi As Literal = CType(e.Item.FindControl("ltrDiaChi"), Literal)
        ltrDiaChi.Text = row.DiaChi

    End Sub

 
End Class
